<!DOCTYPE html>
<html lang="en">
    <head>
		<meta charset="UTF-8">
		<title>服务编辑页面</title>
		<link rel="stylesheet" href="__ADMIN_PATH__/component/pear/css/pear.css" />
	</head>
	<body>
		<form class="layui-form" action="">
			<div class="mainBox">
				<div class="main-container">

					<div class="layui-form-item">
						<label class="layui-form-label"><font color="red">*</font>用户名</label>
						<div class="layui-input-block">
							<input type="text" name="user_name" autocomplete="off" placeholder="请输入用户名" class="layui-input" value="{$info['user_name'] ?= $info['user_name']}" />
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">密码</label>
						<div class="layui-input-block">
							<input type="password" name="password" autocomplete="off" placeholder="请输入密码" class="layui-input" value="" />
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">确认密码</label>
						<div class="layui-input-block">
							<input type="password" name="repassword" autocomplete="off" placeholder="请输入确认密码" class="layui-input" value="" />
						</div>
					</div>




					<div class="layui-form-item">
						<label class="layui-form-label">机构名称</label>
						<div class="layui-input-block">
							<input type="text" name="company_name" autocomplete="off" placeholder="机构名称" class="layui-input"value="{$info['company_name'] ?= $info['company_name']}" />
						</div>
					</div>

					<!--<div class="layui-form-item">-->
					<!--	<label class="layui-form-label">类型</label>-->
					<!--	<div class="layui-input-block">-->
					<!--		<?php $type = isset($info['type']) ? $info['type'] : 0; ?>-->
					<!--		<input type="radio" name="type" value="1" {if condition="$type eq 1"} checked="" {/if} title="分公司" >-->
					<!--		<input type="radio" name="type" value="2" {if condition="$type eq 2"} checked="" {/if} title="加盟商">-->
					<!--	</div>-->
					<!--</div>-->
					
					<input type="hidden" name="type" value="{:input('type')}"/>
					
					<div class="layui-form-item">
						<label class="layui-form-label"><font color="red">*</font>循环周期(每月几号)</label>
						<div class="layui-input-block">
							<input type="text" name="day" autocomplete="off" placeholder="请输入循环周期" class="layui-input" value="{$info['day'] ?= $info['day']}" />
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">平台抽成(%)</label>
						<div class="layui-input-block">
							<input type="number" name="commission" autocomplete="off" placeholder="请输入数字" class="layui-input" value="{$info['commission'] ? $info['commission'] : 0}" />
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">请选择地区</label>
						<div class="layui-input-inline">
							<select name="sheng" lay-filter="sheng">
								<option value="0">请选择省</option>
								{volist name="area" id="vo"}
								{$sheng = isset($info['sheng']) ? $info['sheng'] : 0;}
							     	<option value="{$vo.id}" {if condition="$vo['id'] eq $sheng "} selected {/if}>{$vo.name}</option>
								{/volist}
							</select>
						</div>
						<div class="layui-input-inline">
							<select name="shi" id="shi"  lay-filter="shi">
								<option value="0">请选择市</option>
								{volist name="shi_arr" id="vo"}
								    {$shi = isset($info['shi']) ? $info['shi'] : 0;}
								    <option value="{$vo.id}" {if condition="$vo['id'] eq $shi"} selected {/if}>{$vo.name}</option>
								{/volist}
							</select>
						</div>
					</div>

					<div class="layui-form-item" pane="">
						<label class="layui-form-label">选择区、县</label>
						<div class="layui-input-block" id="qu">
							{$qu_list}
						</div>
					</div>


					<div class="layui-form-item">
						<label class="layui-form-label"><font color="red">*</font>是否为地级市</label>
						<div class="layui-input-block">
							<input lay-filter="expire_type" type="radio" name="is_xian" value="0" title="否" {if condition="isset($info['is_xian']) and $info['is_xian'] eq 0"}checked=""{/if} />
							<input lay-filter="expire_type" type="radio" name="is_xian" value="1" title="是" {if condition="isset($info['is_xian']) and $info['is_xian'] eq 1"}checked=""{/if} />
						</div>
					</div>
				</div>
			</div>

			<div class="bottom">
				<div class="button-container">
					<input type="hidden" name="proxy_id" value="{$info['proxy_id'] ?= $info['proxy_id']}" />
					<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
						lay-filter="service">
						<i class="layui-icon layui-icon-ok"></i>
						提交
					</button>
					<button type="reset" class="pear-btn pear-btn-sm">
						<i class="layui-icon layui-icon-refresh"></i>
						重置
					</button>
				</div>
			</div>

		</form>
		<script src="__ADMIN_PATH__/component/layui/layui.js"></script>
		<script src="__ADMIN_PATH__/component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'jquery', 'popup', 'loading'], function() {
				let form = layui.form;
				let $ = layui.jquery;
				var popup = layui.popup;
				let loading = layui.loading;

				/**
				 * 表单提交
				 */
				form.on('submit(service)', function(data) {
					$.ajax({
						url:"{:url('proxy/save')}",
						type:"POST",
						dataType:"JSON",
						data:data.field,
						beforeSend: function () {
							loading.Load(1, "");
		                },
		                complete: function () {
		                	loading.loadRemove();
		                },
		                success:function(res)
		                {
		                	if(res.code == 0)
		                	{
		                		//正常业务
		                		popup.success(res.msg, function(){
		                			var index = parent.layer.getFrameIndex(window.name);
		                			parent.location.reload();
		                			parent.layer.close(index); //再执行关闭
	                        	});
		                	}else
		                	{
		                		//业务异常
		                		popup.warning(res.msg);
		                	}
		                },
		                error:function()
		                {
		                	loading.loadRemove();
		                	popup.failure('服务器错误');
		                }
		            });
		            return false;
		        });


				form.on('select(sheng)', function (data) {
					$("#qu").html('');
					let id = data.value;
					$.get(`/admin/proxy/area/id/${id}`, function (res) {
						console.log(res)
						let options = '<option value="0">请选择市</option>';
						let templates = res.data;
						for (let template of templates) {
							console.log(template)
							options += `<option value="${template.id}">${template.name}</option>`;
						}
						console.log(options)
						$("#shi").html(options);
						form.render('select');
					}, 'json');
				});

				form.on('select(shi)', function (data) {
					$("#qu").html('');
					let id = data.value;
					let proxy_id = '{$proxy_id}';
					$.get(`/admin/proxy/area_qu/proxy_id/${proxy_id}/id/${id}`, function (res) {
						console.log(res)

						if(res.code == '1') {

							/*
							let html = '';
							let templates = res.data;
							for (let template of templates) {
								console.log(template)
								html +='<input type="checkbox" name="qu['+template.id+']" lay-skin="primary" title="'+template.name+'">'
							}*/

                            html = res.data;
							$("#qu").html(html);
							form.render();
						}else {
							$("#qu").html('');
							popup.warning(res.msg);
						}
					}, 'json');
				});








		    });
		</script>
		<style type="text/css">
			.plug-file-upload-view li
			{
				display: inline;
			}
		</style>
		{include file="publics/ueditor" /}
		<!--编辑器事件必须放到ueditor下面-->
		<script type="text/javascript">
			var editor = UE.getEditor('editor-tag-introduce',{
		    	initialFrameWidth:'100%',
		    	initialFrameHeight:350,
		    	autoFloatEnabled:false,
		    	autoHeightEnabled:false,
		    	serverUrl:"{:url('ueditor/index',['path_type' => !empty($editor_path_type) ? $editor_path_type : 'common'])}"
		    });
		    var editor2 = UE.getEditor('editor-tag-taboos',{
		    	initialFrameWidth:'100%',
		    	initialFrameHeight:350,
		    	autoFloatEnabled:false,
		    	autoHeightEnabled:false,
		    	serverUrl:"{:url('ueditor/index',['path_type' => !empty($editor_path_type) ? $editor_path_type : 'common'])}"
		    });
		    var editor3 = UE.getEditor('editor-tag-notice',{
		    	initialFrameWidth:'100%',
		    	initialFrameHeight:350,
		    	autoFloatEnabled:false,
		    	autoHeightEnabled:false,
		    	serverUrl:"{:url('ueditor/index',['path_type' => !empty($editor_path_type) ? $editor_path_type : 'common'])}"
		    });
		</script>
	</body>
</html>